package com.xmut.eduservice.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xmut.commonutils.R;
import com.xmut.eduservice.entity.AclUser;
import com.xmut.eduservice.entity.EduCourseCollect;
import com.xmut.eduservice.service.EduCourseCollectService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程收藏 前端控制器
 * </p>
 *
 * @author huangchaoqin
 * @since 2020-08-04
 */
@RestController
@RequestMapping("/eduservice/edu-course-collect")
public class EduCourseCollectController {
    @Autowired
    private EduCourseCollectService eduCourseCollectService  ;
     @ApiOperation(value = "获取学生关注课程")
     @GetMapping("getAllByMemberId/{memberid}")
     public R getAllByMemberId(@PathVariable String memberid){
         QueryWrapper<EduCourseCollect>  wrapper = new QueryWrapper<>();
         wrapper.eq("member_id",memberid);
         List<EduCourseCollect> list = eduCourseCollectService.list(wrapper);
         return R.ok().data("list",list);
     }

    @ApiOperation(value = "新增学生关注课程")
    @PostMapping("addCollectInfo")
    public R addCollectInfo(@RequestBody EduCourseCollect eduCourseCollect){
         eduCourseCollectService.save(eduCourseCollect);
        return R.ok();
    }

    @DeleteMapping("deleteCollectInfo/{courseId}/{memberId}")
    public R deleteCollectInfo(@PathVariable String courseId,
                               @PathVariable String memberId) {
        QueryWrapper<EduCourseCollect> wrapper = new QueryWrapper<>();
        wrapper.eq("course_id", courseId);
        wrapper.eq("member_id", memberId);

        eduCourseCollectService.remove(wrapper);
         return R.ok();
    }
}




